/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import modelo.Usuario;
import modelo.persistencia.BIN;

/**
 *
 * @author Andrés
 */
public class VistaInicio extends javax.swing.JFrame {

    BIN bin = new BIN();
    Usuario usuarioBD = new Usuario();

    /**
     * Creates new form VistaInicio
     */
    public VistaInicio() {
        try {
            UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
        } catch (Exception ex) {
            System.err.println("adsf");
        }
        initComponents();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setResizable(false);
        setVisible(true);
        setLocationRelativeTo(null);
        iniciarLogo();

        numeroPuerto.setText("1521");
        //if(this.recordarme.isSelected()){
        bin = new BIN();
        usuarioBD = (Usuario) bin.leer();
        if (usuarioBD.getRecordar()) {
            this.recordarme.setSelected(true);
            this.nombreUsuario.setText(usuarioBD.getUser());
            this.contrasenaUsuario.setText(usuarioBD.getPassword());
            this.numeroPuerto.setText(usuarioBD.getPuerto());
        }

        //}
    }

    public final void iniciarLogo() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("./image/logo.png")));
    }

    public void agregarListenerBotonAceptar(ActionListener listener) {
        this.botonAceptar.addActionListener(listener);
    }

    public void agregarListenerItemCerrar(ActionListener actionListener) {
        this.itemCerrar.addActionListener(actionListener);
    }

    public void agregarListenerItemAcerdaDe(ActionListener actionListener) {
        this.itemAcercaDe.addActionListener(actionListener);
    }

    public String obtenerNombre() {
        return this.nombreUsuario.getText();
    }

    public String obtenerDireccion() {
        return this.direccionBD.getText();
    }

    public String obtenerContrasena() {
        char[] pass = this.contrasenaUsuario.getPassword();
        String contrasena = "";
        for (int i = 0; i < pass.length; i++) {
            contrasena += pass[i];
        }
        return contrasena;
    }

    public void errorContrasenna() {
        JOptionPane.showMessageDialog(null, "Vuelva a introducir los datos", "Datos Incorrectos", 0);
    }

    public void errorDireccion() {
        JOptionPane.showMessageDialog(null, "Direccion IP no disponible actualmente", "Datos Incorrectos", 0);
        direccionBD.setText("localhost");
    }

    public void activarBarra() {
        UIManager.put("ProgressBar.repaintInterval", new Integer(100));
        UIManager.put("ProgressBar.cycleTime", new Integer(3500));
        jProgressBar1.setIndeterminate(true);
        jProgressBar1.setString("Cargando...");
        jProgressBar1.setStringPainted(true);
        jProgressBar1.setForeground(Color.BLUE);
    }

    public String obtenerPuerto() {
        return this.numeroPuerto.getText();
    }

    public void mostrarErrorDeCredenciales() {
        JOptionPane.showMessageDialog(null, "Por favor verifique los datos que ingresó", "Error de credenciales", JOptionPane.ERROR_MESSAGE, null);
    }

    public void notificarRespaldo() {
        jProgressBar1.setString("Realizando Respaldos...");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        etiquetaTitulo = new javax.swing.JLabel();
        botonAceptar = new javax.swing.JButton();
        recordarme = new javax.swing.JRadioButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel3 = new javax.swing.JPanel();
        imageOracle = new javax.swing.JLabel();
        nombreUsuario = new javax.swing.JTextField();
        etiquetaNombre = new javax.swing.JLabel();
        etiquetaContrasena = new javax.swing.JLabel();
        contrasenaUsuario = new javax.swing.JPasswordField();
        etiquetadireccion = new javax.swing.JLabel();
        direccionBD = new javax.swing.JTextField();
        numeroPuerto = new javax.swing.JTextField();
        etiquetaPuerto = new javax.swing.JLabel();
        menu = new javax.swing.JMenuBar();
        menuArchivo = new javax.swing.JMenu();
        itemCerrar = new javax.swing.JMenuItem();
        menuAyuda = new javax.swing.JMenu();
        itemAcercaDe = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Monitor Administración Bases de Datos");

        etiquetaTitulo.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        etiquetaTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        etiquetaTitulo.setText("Oracle - Monitor Multipropósito");

        botonAceptar.setText("Iniciar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        recordarme.setText("Recordarme");
        recordarme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recordarmeActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        imageOracle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/image/oracle_logo.gif"))); // NOI18N
        imageOracle.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        etiquetaNombre.setText("Usuario:");

        etiquetaContrasena.setText("Contraseña:");

        etiquetadireccion.setText("Direccion IP:");

        direccionBD.setText("localhost");

        etiquetaPuerto.setText("Puerto:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imageOracle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(etiquetaContrasena)
                            .addComponent(etiquetaNombre))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nombreUsuario)
                            .addComponent(contrasenaUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(etiquetadireccion)
                            .addComponent(etiquetaPuerto))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(direccionBD)
                            .addComponent(numeroPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nombreUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(etiquetaNombre))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(contrasenaUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(etiquetaContrasena))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(etiquetadireccion)
                            .addComponent(direccionBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(numeroPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(etiquetaPuerto)))
                    .addComponent(imageOracle))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(etiquetaTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(190, 190, 190)
                        .addComponent(recordarme)
                        .addGap(18, 18, 18)
                        .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(etiquetaTitulo)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(recordarme, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botonAceptar, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        menuArchivo.setText("Archivo");

        itemCerrar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        itemCerrar.setText("Cerrar");
        menuArchivo.add(itemCerrar);

        menu.add(menuArchivo);

        menuAyuda.setText("Ayuda");

        itemAcercaDe.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        itemAcercaDe.setText("Acerca de");
        menuAyuda.add(itemAcercaDe);

        menu.add(menuAyuda);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botonAceptarActionPerformed

    private void recordarmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recordarmeActionPerformed
        BIN bin = new BIN();
        if (this.recordarme.isSelected()) {
            this.usuarioBD.setRecordar(true);
            bin.escribir(this.usuarioBD);
        } else {
            this.usuarioBD.setRecordar(false);
            bin.escribir(this.usuarioBD);
        }
    }//GEN-LAST:event_recordarmeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VistaInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VistaInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VistaInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VistaInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaInicio().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JPasswordField contrasenaUsuario;
    private javax.swing.JTextField direccionBD;
    private javax.swing.JLabel etiquetaContrasena;
    private javax.swing.JLabel etiquetaNombre;
    private javax.swing.JLabel etiquetaPuerto;
    private javax.swing.JLabel etiquetaTitulo;
    private javax.swing.JLabel etiquetadireccion;
    private javax.swing.JLabel imageOracle;
    private javax.swing.JMenuItem itemAcercaDe;
    private javax.swing.JMenuItem itemCerrar;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenu menuArchivo;
    private javax.swing.JMenu menuAyuda;
    private javax.swing.JTextField nombreUsuario;
    private javax.swing.JTextField numeroPuerto;
    private javax.swing.JRadioButton recordarme;
    // End of variables declaration//GEN-END:variables
}
